package com.example.exp_2;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Comment extends AppCompatActivity {
    public String[] names = new String[]{"贾奥","周经纬"};
    public String[] times = new String[]{"2021.10.09 07:00","2021.10.09 09:00"};
    public String[] comments = new String[]{"今天天气怎么样","今天不下雨"};
    public int[] imageId = new int[]{R.drawable.ic_baseline_account_circle_24,R.drawable.ic_baseline_account_circle_24};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.comment);
        List<Map<String,Object>> listItems = new ArrayList<>();
        for (int i = 0;i < names.length;i++) {
            Map<String,Object> listItem = new HashMap<>();
            listItem.put("head",imageId[i]);
            listItem.put("name",names[i]);
            listItem.put("time",times[i]);
            listItem.put("comment",comments[i]);
            listItems.add(listItem);
        }
        SimpleAdapter simpleAdapter = new SimpleAdapter(this,listItems,R.layout.singlecomment,new String[]{"head","name","time","comment"},new int[]{R.id.head,R.id.name,R.id.time,R.id.comment});
        ListView list = findViewById(R.id.mylist);
        list.setAdapter(simpleAdapter);
    }
}
